﻿using MC.Warehouse.Core;
using System.Windows;

namespace MC.Warehouse.ViewModels
{
    public class MainWindowViewModel : WindowViewModel
    {
        public MainWindowViewModel()
        {
            TabbarManager.OpenTab(Contant.HomeView,"Home");
        }

        private RelayCommand _logout;
        public RelayCommand Logout
        {
            get { return _logout ?? (_logout = new RelayCommand(para => Restart())); }
        }
        private void Restart()
        {
            MenuManager.Clean();
            ToolbarManager.Clean();
            TabbarManager.Clean();
            DataGridBehavior.Clean();
            Application.Current.MainWindow = TabbarManager.CreateInstance("LoginView") as Window;
            var window = Application.Current.Windows[0];
            if (window != null) window.Close();
            if (Application.Current.MainWindow != null) Application.Current.MainWindow.Show();
        }

        private RelayCommand _exit;
        public RelayCommand Exit
        {
            get { return _exit ?? (_exit = new RelayCommand(para => Close())); }
        }

        private static void Close()
        {
            Application.Current.Shutdown();
        }

        public int TabitemSelected 
        {
            get
            {
                return TabbarManager.SelectedIndex;
            }
            set
            {
                TabbarManager.SelectedIndex = value;
                NotifyPropertyChanged("TabitemSelected");
            }
        }

        //private void KeyEvent(KeyEventArgs e)
        //{
        //    if (e.Key == Key.Tab && (Keyboard.Modifiers & (ModifierKeys.Control | ModifierKeys.Shift)) == (ModifierKeys.Control | ModifierKeys.Shift))
        //    {
        //        MessageBox.Show("CTRL + SHIFT + TAB trapped");
        //    }

        //    if (e.Key == Key.F && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
        //    {
                
        //    }
        //}
    }
}
